package com.sh.apiconsume.service;

import com.google.gson.Gson;
import com.sh.apicommon.service.ApiBackendService;
import com.sh.apiconsume.model.UpdateInvokeToJMS;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class JmsInvokeCountConsumer {
    @DubboReference
    private ApiBackendService apiBackendService;
    @JmsListener(destination = "invokeCountConsumer")
    public void invokeCountConsumer(String message) {
        Gson gson = new Gson();
        UpdateInvokeToJMS messageBean = gson.fromJson(message, UpdateInvokeToJMS.class);
        log.info("invokeCountConsumer 接收到消息：{}", messageBean);
        boolean b = apiBackendService.invokeCount(messageBean.getUserId(), messageBean.getInterfaceInfoId());
        if (b){
            log.info("invokeCountConsumer 更新成功");
        }else {
            log.info("invokeCountConsumer 更新失败");
        }
    }



}
